package com.henau;

import com.henau.dao.IRoadLineMapper;
import com.henau.domain.RoadLine;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.Reader;
import java.util.Date;
import java.util.List;

public class test3 {
    private Reader reader = null;
    private SqlSession sqlSession = null;
    private IRoadLineMapper mapper = null;

    @Before
    public void init() throws IOException {
        reader = Resources.getResourceAsReader("SqlMapConfig.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
        sqlSession = factory.openSession();
        mapper = sqlSession.getMapper(IRoadLineMapper.class);
    }

    @After
    public void destroy() throws IOException {
        sqlSession.commit();
        sqlSession.close();
        reader.close();
    }
    @Test
    public void findAll() throws Exception{
        List<RoadLine> all = mapper.findAll();
        for (RoadLine roadline :all) {
            System.out.println(roadline);

        }
    }
    @Test
    public void findRoadLineByName() throws Exception{
        RoadLine byName = mapper.findRoadLineByName("43路");
        System.out.println(byName);
    }
    @Test
    public void addRoadLine() throws Exception{
        RoadLine roadline = new RoadLine("运行类型4","张云奇公司","88路","路线类型2","张云奇公司","正常",6.5,6.7,new Date(),new Date(),new Date(),new Date());
        int i = mapper.addRoadLine(roadline);
        System.out.println(i);
    }
    @Test
    public void deleteRoadLine() throws Exception{
        int i = mapper.deleteRoadLine("88路");
        System.out.println(i);
    }
    @Test
    public void upadteRoadLine() throws Exception{
        RoadLine roadLineByName = mapper.findRoadLineByName("43路");
        roadLineByName.setOfCompany("薛西龙公司");
        int i = mapper.updateRoadLine(roadLineByName);
        System.out.println(i);
    }
}